package com.longcai.piaojia.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.DepositListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/10/12.
 */
public class DespositGridAdapter extends ArrayAdapter<DepositListGet.DespoistEntity> {

    private LayoutInflater layoutInflater;
    private Context context;
    public int selPosition = -1;

    public DespositGridAdapter(Context context, List<DepositListGet.DespoistEntity> lists) {
        super(context, 0, lists);

        this.context = context;

        layoutInflater = ((Activity)context).getLayoutInflater();



    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        DepositListGet.DespoistEntity despoistEntity = getItem(position);

        if(convertView == null){

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_desposit_grid, null)));

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) convertView.getTag();

        }

        if (selPosition == position){

//            viewHolder.item_desposit_grid_tv.setTextColor(context.getResources().getColor(R.color.theme_color));
//            viewHolder.item_desposit_give_tv.setTextColor(context.getResources().getColor(R.color.theme_color));
            viewHolder.desposit_grid_ll.setBackgroundResource(R.drawable.rectangle_white_theme_color_stroke);

        } else {

//            viewHolder.item_desposit_grid_tv.setTextColor(context.getResources().getColor(R.color.text_color));
//            viewHolder.item_desposit_give_tv.setTextColor(context.getResources().getColor(R.color.hint_color));
            viewHolder.desposit_grid_ll.setBackgroundResource(R.drawable.rectangle_white_no_stroke);

        }

        viewHolder.item_desposit_grid_tv.setText(despoistEntity.money + context.getString(R.string.goods_info_money_text));
        viewHolder.item_desposit_give_tv.setText(context.getString(R.string.desposit_give_text) + despoistEntity.present + context.getString(R.string.goods_info_money_text));

        return convertView;

    }

    private class ViewHolder{

        @BoundView(R.id.item_desposit_grid_tv) public TextView item_desposit_grid_tv;
        @BoundView(R.id.item_desposit_give_tv) public TextView item_desposit_give_tv;
        @BoundView(R.id.desposit_grid_ll) public LinearLayout desposit_grid_ll;

    }

}
